<template>
	<view class="rentDetail">
		<view class="swiperBox">
			<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000" style="height: 100%;">
				<swiper-item @click="amplification" v-for="(item,i) in imgs" :key='i'>
					<image :src="item" mode=""></image>
					<view class="imgLeng">{{i+1}}/{{imgs.length}}</view>
				</swiper-item>
				<swiper-item v-for="(v,i) in videos" :key='i'>
					<video :src="v" autoplay="true"></video>
				</swiper-item>
			</swiper>
			<!-- <image :src="data.cover" mode=""></image> -->
		</view>
		<view class="content">
			<view class="title line2">
				{{data.title}}
			</view>
			<view class="describe">
				{{data.desc}}
			</view>
			<view class="priceBox disFlex">
				<view>
					<text class="price" style="font-size: 50rpx;">{{data.price}}</text>
					<text class="numbers">/件/天</text>
					<text class="word" style="color: #ccc;">非会员价</text>
					<text class="word">押金{{data.deposit}}元/件</text>
					<text class="word">{{data.min}}件起租</text>
				</view>
				
				<text class="word">库存{{data.surplus_number}}</text>
			</view>
			<view  class="priceBox" style="margin-top: -5rpx;">
				<text class="price">{{data.member_price==null?data.price:data.member_price}}</text>
				<text class="numbers" style="color: #FE7203;font-size: 20rpx;">/件/天</text>
				<text class="word" style="color: red;">会员价</text>
			</view>
		</view>
		<view class="box10">
			<view class="info">
				<view class="left">规格型号</view>
				<view class="right">{{data.spec}}</view>
			</view>
		</view>
		<view class="box10">
			<view class="remark">
				<view class="title">标准件介绍</view>
				<view class="list">
					<view class="listText" v-html="data.content">
					</view>
				</view>
			</view>
		</view>

		<view class="bottom">
			<image class="icon_dh" src="../../../static/img/icon_dh.png" mode="" @tap="phone"></image>
			<button @tap="showPop">添加至租赁清单</button>
		</view>

		<view class="popBox" @tap="isshow" v-if="pop">
			<view class="pop" @tap.stop="">
				<view class="close">
					<text class="iconfont icon-untitled94" @tap="isshow">x</text>
				</view>
				<view class="goodsInfo">
					<image :src="data.cover" mode=""></image>
					<view>
						<view class="price">{{data.price}}</view>
						<view>
							<text class="word">{{data.min}}件起租</text>
							<text class="word paddingLeft5">押金{{data.deposit}}元/件</text>
						</view>
						<view class="word">库存{{data.surplus_number}}</view>
					</view>
				</view>
				<view class="numberBox disFlex">
					<view class="title">租赁数量：</view>
					<view class="btns">
						<button class="reduce" @click.stop="change('-')">-</button>
						<view class="number">{{number}}</view>
						<button class="add" @click.stop="change('+')">+</button>
					</view>
				</view>
				<button class="sure" @tap.stop="go">确定</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pop: false,
				number: 1,
				data: '',
				imgs:[],
				videos:[]
			}
		},
		onLoad(option) {
			console.log(option.id)
			this.getinfo(option.id)
		},
		methods: {
			amplification(e) {
				// 预览图片
				let urls=[]
				this.imgs.map((v,i)=>{
					if(v==e){
						urls.unshift(v)
					}else{
						urls.push(v)
					}
				})
				uni.previewImage({
					urls: urls,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			getinfo(v) {
				this.http('/api/standard/read', 'post', {
						id: v
					}, )
					.then((res) => {
						this.data = res.data
						this.data.carousel.map((i)=>{
							if(i.type=='video'){
								this.videos.push(i.url) 
							}else{
								this.imgs.push(i.url)
							}
						})
						console.log(this.data)
					})
			},
			go() {
				
				if(this.number>0){
					this.http('/api/standard_order/add_rent', 'post', {
							id: this.data.id,
							number: this.number,
						}, )
						.then((res) => {
							console.log(res)
							if(res.sta==200){
								this.pop=false;
								console.log(this.pop)
								uni.showToast({
									title: '添加成功',
									icon: 'none'
								})
							}else{
								uni.showToast({
									title:res.msg,
									icon: 'none'
								})
							}
						})
				}else{
					uni.showToast({
						title: '请添加数量',
						icon: 'none'
					})
				}
				
			},
			showPop() {
				let token = uni.getStorageSync('userinfo').token
				if(token==undefined){
				console.log(1)
				this.getnav(this.router(`login`))
					uni.showToast({
						title:'请登录后重新尝试',
						icon: 'none'
					})
				}else{
					this.pop = true;
				}
			},
			closePop() {
				this.pop = false;
			},
			change(v) {
				if (v == '+') {
					this.number = this.number + 1
				} else {
					if (this.number > 0) {
						this.number = this.number - 1
					}
				}

			},
			phone(){
						 uni.makePhoneCall({
						     phoneNumber: this.data.service_phone
						 });
			},
			isshow(){
				this.pop=false
			},
		}
	}
</script>

<style lang="less">
	.bottomimg {
		text-align: center;
	}

	.list {
		display: flex;
		padding-bottom: 40rpx;
	}

	.rentDetail {
		padding-bottom: 100rpx;

		.swiperBox {
			height: 500rpx;
			position: relative;

			image,
			video {
				width: 100%;
				height: 100%;
			}

			.imgLeng {
				position: absolute;
				z-index: 99;
				right: 40rpx;
				bottom: 40rpx;
				width: 120rpx;
				height: 54rpx;
				background: rgba(0, 0, 0, .3);
				text-align: center;
				line-height: 54rpx;
				color: #fff;
			}
		}

		.content {
			padding: 40rpx 40rpx 30rpx 40rpx;

			.title {
				font-size: 48rpx;
				font-weight: bold;
			}

			.describe {
				margin-top: 40rpx;
				color: rgba(190, 201, 215, 1);
			}

			.priceBox {
				margin-top: 25rpx;

				.price {
					color: #FE7203;

					&::before {
						// padding-right: 5rpx;
						font-size: 36rpx;
					}
				}

				.numbers {
					color: #FE7203;
					font-size: 20rpx;
				}

				.word {
					font-size: 24rpx;
					color: #BEC9D7;
					padding-left: 10rpx;
				}
			}
		}

		.info {
			height: 112rpx;
			display: flex;
			align-items: center;
			padding: 0 40rpx;

			.left {
				font-size: 32rpx;
				color: rgba(190, 201, 215, 1);
			}

			.right {
				margin-left: 54rpx;
				font-size: 32rpx;
				color: rgba(38, 38, 38, 1);
			}

			.labels {
				display: flex;
				align-items: center;
				margin-left: 54rpx;

				>view {
					text-align: center;
					background: rgba(254, 114, 3, .1);
					// opacity:0.1;
					border-radius: 10rpx;
					color: rgba(254, 114, 3, 1);
					padding: 8rpx;
				}
			}
		}

		.remark {
			width: 100%;
			padding: 40rpx;

			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: rgba(38, 38, 38, 1);
			}
			.listText{
			}
		}

		.bottom {
			position: fixed;
			bottom: 0;
			height: 90rpx;
			width: 100%;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			background-color: #fff;
			
			.icon_dh {
				width: 40rpx;
				height: 40rpx;
				
				margin-left: 40rpx ;
			}

			button {
				flex: 1;
				margin-left: 40rpx;
				outline: none;
				border: 0;
				border-radius: 0;
				line-height: 90rpx;
				background-color: #2291FF !important;
				color: #fff;
				font-size: 32rpx;
			}
		}

		.popBox {
			position: fixed;
			top: 0;
			left: 0;
			bottom: 0;
			right: 0;
			background: rgba(0, 0, 0, .3);
			z-index: 999;

			.pop {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				z-index: 99;
				background-color: #fff;
				padding: 0 40rpx;

				.close {
					margin-top: 20rpx;
					text-align: right;

					.iconfont {

						font-size: 30rpx;
						font-weight: bold;
					}
				}

				.goodsInfo {
					display: flex;
					align-items: center;
					margin-top: 20rpx;
					image {
						width: 200rpx;
						height: 200rpx;
						border-radius: 10rpx;
					}

					>view {
						display: flex;
						height: 200rpx;
						flex-direction: column;
						justify-content: space-between;
						padding: 30rpx 0;
						margin-left: 30rpx;

						.price {
							color: #FE7203;

							&::before {
								font-size: 20rpx;
							}

							&::after {
								content: '/件/天';
								font-size: 20rpx;
							}
						}

						.word {
							font-size: 24rpx;
							color: rgba(190, 201, 215, 1);
						}
					}
				}

				.numberBox {
					margin-top: 102rpx;

					.title {
						font-size: 32rpx;
					}

					.btns {
						display: flex;
						align-items: center;

						button {
							border-radius: 10rpx;
							outline: none;
							border: none;
							background: rgba(245, 245, 249, 1) !important;
							text-align: center;
							line-height: 56rpx;
						}

						.reduce,
						.add {
							width: 56rpx;
							height: 56rpx;
						}

						.number {
							text-align: center;
							margin: 0 10rpx;
							width: 120rpx;
						}
					}
				}

				.sure {
					width: 100%;
					height: 90rpx;
					background: rgba(34, 145, 255, 1) !important;
					border-radius: 10rpx;
					line-height: 90rpx;
					outline: none;
					border: none;
					margin-top: 160rpx;
					color: #fff;
					font-size: 32rpx;
				}
			}
		}
	}
</style>
